/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.node;

import 解析.Matcher;

/**
 *
 * @author yanxi
 */
public class StartS extends Start { 
    public StartS(Node node) {
        super(node);
    }

    @Override
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        if (i > matcher.to - minLength) {
            matcher.hitEnd = true;
            return false;
        }
        int guard = matcher.to - minLength;
        while (i <= guard) {
            //if ((ret = next.match(matcher, i, seq)) || i == guard)
            if (next.match(matcher, i, seq)) {
                matcher.first = i;
                matcher.groups[0] = matcher.first;
                matcher.groups[1] = matcher.last;
                return true;
            }
            if (i == guard) {
                break;
            }
            // Optimization to move to the next character. This is
            // faster than countChars(seq, i, 1).
            if (Character.isHighSurrogate(seq.charAt(i++))) {
                if (i < seq.length()
                        && Character.isLowSurrogate(seq.charAt(i))) {
                    i++;
                }
            }
        }
        matcher.hitEnd = true;
        return false;
    }
}
